﻿using System;
using System.Collections.Generic;
using System.Drawing;
using XFControls.Utils;
using XFControls.XFPanels.XFPanelItems;

namespace XFSenseUI.XFItems.SenseControls
{
    [Flags]
    public enum SenseControlModalButtons
    {
        Close = 0,
        Ok = (1 << 0),
        Cancel = (1 << 1),
        Yes = (1 << 2),
        No = (1 << 3)
    }

    public class SenseControlModal : SenseItemBase
    {
        public string Title { get; set; }
        public SenseControl Control { get; set; }

        private SenseControlModalButtons _buttons;

        public SenseControlModal(SenseControlModalButtons buttons)
        {
            _buttons = buttons;
            Style = new XFItemStyle
                    {
                Padding = 40,
                PaddingBottom = 20,
                PaddingTop = 20,
                TextFont = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Regular),
                TextColor = Color.White,
                TextAlign = XFItemTextAlign.Center
            };
        }

        public override void ItemPaint(Graphics g, int x, int y)
        {
            List<SenseControlButton> buttons = new List<SenseControlButton>();
            g.DrawBlackout(Parent.Parent.ClientRectangle);
            int width = GetWidth(false) - (Style.PaddingLeft + Style.PaddingRight);

            Rectangle buttonsRec = new Rectangle(0, 0, width, 0);

            if ((_buttons & SenseControlModalButtons.Cancel) == SenseControlModalButtons.Cancel)
            {
                var button = new SenseControlButton("Cancel");
                buttons.Add(button);
            }
            if ((_buttons & SenseControlModalButtons.Close) == SenseControlModalButtons.Close)
            {
                var button = new SenseControlButton("Close");
                buttons.Add(button);
            }
            if ((_buttons & SenseControlModalButtons.No) == SenseControlModalButtons.No)
            {
                var button = new SenseControlButton("No");
                buttons.Add(button);
            }
            if ((_buttons & SenseControlModalButtons.Yes) == SenseControlModalButtons.Yes)
            {
                var button = new SenseControlButton("Yes");
                buttons.Add(button);
            }
            if ((_buttons & SenseControlModalButtons.Ok) == SenseControlModalButtons.Ok)
            {
                var button = new SenseControlButton("Ok");
                buttons.Add(button);
            }

            buttonsRec.Width = (width / buttons.Count) - (Style.PaddingLeft + Style.PaddingRight);
        }
    }
}
